﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using PA3PC113.Untity;
using System.Data;

namespace PA3PC113
{

    public class basPA3PC113
    {
        //    public OraSession           As Object
        //public OraDatabase          As Object
        Makelog m = new Makelog();
        basPA3PC113_2 basPA3PC113_2 = new basPA3PC113_2();
        public string MyProgramName = "PA3PC113";
        public string MyPcName;

        public string PNAME = "PA3PC113-";
        public string MachineNo;
        public int CURING_Mode;
        public string SHIFT1_START_TIME;
        public string SHIFT2_START_TIME;
        public string SHIFT3_START_TIME;

        public string GHostName;
        public int Counter;
        public string PlantName;
        public string FontFontName;
        public int CureSheduleM_Found;

        public int ERR_DB;
        [DllImport("kernel32.dll", EntryPoint = "GetComputerNameA", SetLastError = true)]
        private static extern long GetComputerName(string lpBuffer, long nSize);
        private int MAX_COMPUTERNAME_LENGTH = 15;
        private long lngSizLen;


        public string G_Log_File;
        public string G_EventLog_File;

        public int G_CureAct_TCD;
        public int G_CureAct_MCG;
        [DllImport("kernel32.dll", EntryPoint = "GetPrivateProfileIntA", SetLastError = true)]
        public static extern int GetPrivateProfileInt(string lpApplicationName, string lpKeyName, int nDefault, string lpFileName);
        [DllImport("kernel32.dll", EntryPoint = "GetPrivateProfileStringA", SetLastError = true)]
        public static extern int GetPrivateProfileString(string lpApplicationName, string lpKeyName, string lpDefault, string lpReturnedString, int nSize, string lpFileName);
        public int G_DF_Cur;
        public void GetCureIni()
        {
            int rtn;
            string InitData = ""; ;
            string EMsg;
            //GetCureIni = 1;
            rtn = GetPrivateProfileString("LOG", "LogFile_Path", "", InitData, InitData.Length, "Curing.ini");
            //If Trim(Left(InitData, rtn) <> "") Then
            //    G_Log_File = Trim(Left(InitData, rtn))
            //Else
            //    G_Log_File = "D:\BossGeteWay\LOG\Curing\"
            //End If

            rtn = GetPrivateProfileString("LOG", "EventLogFile_Path", "", InitData, InitData.Length, "Curing.ini");
            //If Trim(Left(InitData, rtn) <> "") Then
            //    G_EventLog_File = Trim(Left(InitData, rtn))
            //Else
            //    G_EventLog_File = "D:\BossGeteWay\LOG\Curing\"
            //End If

            //'    G_Df_Type = GetPrivateProfileInt("DF", "Type", 0, "Curing.ini")
            G_DF_Cur = GetPrivateProfileInt("DF", "DF_Cur", 6, "Curing.ini");

            G_CureAct_TCD = GetPrivateProfileInt("CureActual", "TCD", -1, "Curing.ini");
            if (G_CureAct_TCD == -1)
            {
                EMsg = "No data exist in the Curing.ini file";
                EMsg = EMsg + "KeyBlock=CureActual";
                EMsg = EMsg + "Key=TCD";
                EMsg = EMsg + "Fix curing.ini file and executes the program again.";
                //MsgBox EMsg, vbCritical;
            }

            G_CureAct_MCG = GetPrivateProfileInt("CureActual", "MCG", -1, "Curing.ini");
            if (G_CureAct_TCD == -1)
            {
                EMsg = "No data exist in the Curing.ini file";
                EMsg = EMsg + "KeyBlock=CureActual";
                EMsg = EMsg + "Key=MCG";
                EMsg = EMsg + "Fix curing.ini file and executes the program again.";
                //MsgBox EMsg, vbCritical
            }

            if (G_CureAct_TCD == -1 || G_CureAct_MCG == -1)
            {
                //GetCureIni = -1;
            }

            // ErrorLogFile = G_Log_File & ErrorLogFile0
            //sqlLogFile = G_Log_File & SqlLogFile0
            //MessageLogFile = G_Log_File & MessageLogFile0
            //ErrorResultLogFile = G_Log_File & ErrorResultLogFile0
            //FileSendProcess = G_Log_File & FileSendProcess0

        }
        /// <summary>
        /// 
        /// </summary>
      public  void GetNamingMaster()
        {
            long lngRet;
            int open_flag;
            long RetryOK_NG;
            long START_TIME;
            DataTable derw = new DataTable();

            open_flag = 0;
            string sSQL = "";

            sSQL = "SELECT CLASSIFICATION1, CLASSIFICATION2, CLASSIFICATION3, NAMING1, NAMING2 FROM NAMINGMASTER ";
            sSQL = sSQL + " WHERE CLASSIFICATION1='B' and CLASSIFICATION3 = '01' ORDER BY NAMING1 ";
            try
            {
                derw = DBUtilityOracle.DBUtilityOra.QueryTable(sSQL.ToString());

                if (derw.Rows.Count == 0)
                {
                    PlantName = "0000";// Space$(4);
                }
                else
                {
                    PlantName = derw.Rows[0]["NAMING1"].ToString() == "" ? "0000" : derw.Rows[0]["NAMING1"].ToString();

                }
            }
            catch (Exception ex)
            {
                PlantName = "0000";
                string meg = "GetNamingMaster";
                string meg1 = ex.ToString();
                m.MakeLog(2, meg,meg1);
            }
        }
        /// <summary>
        /// 暂时没法调用此方法
        /// </summary>
      public void GetMenuServerJob()
      {
          long lngRet;
          int open_flag;
          long RetryOK_NG;
          long START_TIME;

          DataTable der = new DataTable();
          open_flag = 0;
          string sSQL = "";
          sSQL = "SELECT SERVERNAME FROM MENUSERVERJOB";
          sSQL = sSQL + " WHERE JOBNAME = CLOCKADJ";
          try
          {
              der = DBUtilityOracle.DBUtilityOra.QueryTable(sSQL.ToString());

              if (der.Rows.Count == 0)
              {
                  GHostName = GHostName;
              }
              else
              {
                  GHostName = der.Rows[0]["SERVERNAME"].ToString() == "" ? GHostName : der.Rows[0]["SERVERNAME"].ToString();
              }
          }
          catch(Exception ex)
          {
              GHostName = GHostName;
              string msg = "GetMenuServerJob";
              string msg1 = ex.ToString();
              m.MakeLog(2,msg,msg1);
          }
          
      }
        /// <summary>
        ///
        /// </summary>
        /// <param name="TcdRst"></param>
        /// <param name="NowProductionCodeL"></param>
        /// <param name="NowProductionCodeR"></param>
      public void GetNowProductionCode(MesRst TcdRst, out string NowProductionCodeL, out string NowProductionCodeR)
      {
          long lngRet;
          int open_flag;
          long RetryOK_NG;
          open_flag = 0;
          DataTable dt1 = new DataTable();
          string sSQL = "";
          sSQL = "SELECT NowProductionCodeL, NowProductionCodeR";
          sSQL = sSQL + " FROM CuringMachineStatus";
          sSQL = sSQL + " WHERE CurePress = " + TcdRst.MachineNo + "";
          try
          {
              dt1 = DBUtilityOracle.DBUtilityOra.QueryTable(sSQL.ToString());

              if (dt1.Rows.Count == 0)
              {
                  NowProductionCodeL = "";
                  NowProductionCodeR = "";
              }
              else
              {
                  NowProductionCodeL = dt1.Rows[0]["NowProductionCodeL"].ToString() == "" ? "" : dt1.Rows[0]["NowProductionCodeL"].ToString(); //CStr(IIf(IsNull(OraDynaset.Fields("NowProductionCodeL")), _"", OraDynaset.Fields("NowProductionCodeL")))
                  NowProductionCodeR = dt1.Rows[0]["NowProductionCodeR"].ToString() == "" ? "" : dt1.Rows[0]["NowProductionCodeR"].ToString();// CStr(IIf(IsNull(OraDynaset.Fields("NowProductionCodeR")), _"", OraDynaset.Fields("NowProductionCodeR")))
              }
          }
          catch(Exception ex)
          {
              ERR_DB = 1;
              NowProductionCodeL = "";
              NowProductionCodeR = "";
              string msgs = "GetNowProductionCode";
              string msgs1 = ex.ToString();
              m.MakeLog(2,msgs,msgs1);
          }
         
      }
        /// <summary>
        /// 
        /// </summary>
      public void GetCommonParameterC1()
      {

          long lngRet;
          int open_flag;
          long RetryOK_NG;
          long START_TIME;
          DataTable cda = new DataTable();
          open_flag = 0;

          string sSQL = "";
          sSQL = "SELECT PARAMETER1, PARAMETER2, PARAMETER3 FROM COMMONPARAMETER";
          sSQL = sSQL + " WHERE PARAMETERKEY = C1";
          try
          { 
                  cda = DBUtilityOracle.DBUtilityOra.QueryTable(sSQL.ToString());
                  if (cda.Rows.Count==0)
                  {
                      SHIFT1_START_TIME = "0830";
                      SHIFT2_START_TIME = "1630";
                      SHIFT3_START_TIME = "2430";
                  }
                  else
                  {
                      START_TIME =cda.Rows[0]["PARAMETER1"].ToString()=="" ? 830:long.Parse(cda.Rows[0]["PARAMETER1"].ToString());
                      SHIFT1_START_TIME =START_TIME.ToString().PadLeft(4,'0');
                      START_TIME = cda.Rows[0]["PARAMETER2"].ToString()=="" ? 1630:long.Parse(cda.Rows[0]["PARAMETER2"].ToString());
                      SHIFT2_START_TIME =START_TIME.ToString().PadLeft(4,'0');
                      START_TIME =cda.Rows[0]["PARAMETER3"].ToString()=="" ? 30:long.Parse(cda.Rows[0]["PARAMETER3"].ToString());
                      SHIFT3_START_TIME =START_TIME.ToString().PadLeft(4,'0');
                      if  (SHIFT3_START_TIME.Substring(1,2).ToString() == "00")
                      {
                          SHIFT3_START_TIME = "24" + SHIFT3_START_TIME.Substring(3, 4);
                      }
                  }
          }
          catch(Exception ex)
          {
              SHIFT1_START_TIME = "0830";
              SHIFT2_START_TIME = "1630";
              SHIFT3_START_TIME = "2430";
              string msgs = "GetCommonParameterC1";
              string msgs1 = ex.ToString();
              m.MakeLog(2,msgs,msgs1);
          }
        
      }
        /// <summary>
        /// 
        /// </summary>
      public void GetCommonParameter()
      {

          long lngRet;
          int open_flag;
          long RetryOK_NG;


          open_flag = 0;
          DataTable dert = new DataTable();
          CURING_Mode = 0;
          //'' serch database
          string sSQL = "";
          sSQL = "SELECT PARAMETER1 FROM COMMONPARAMETER";
          sSQL = sSQL + " WHERE PARAMETERKEY = KY";
          try
          {
              dert = DBUtilityOracle.DBUtilityOra.QueryTable(sSQL.ToString());

              // '' No serch data
              if (dert.Rows.Count == 0)
              {
                  CURING_Mode = 5;
              }
              else
              {
                  CURING_Mode = dert.Rows[0]["PARAMETER1"].ToString() == "" ? 5 : int.Parse(dert.Rows[0]["PARAMETER1"].ToString());
              }
          }
          catch(Exception ex)
          {
              CURING_Mode = 5;
              string msgs = "GetCommonParameter";
              string msgs1 = ex.ToString();
              m.MakeLog(2,msgs,msgs1);
          }
         
      }
        /// <summary>
        /// 没有调用过此方法
        /// </summary>
      public void Main()
      {
          int intRet;
          int imode;


          string Buffer;
          long sz;
          long rtn1;

          //    sz = MAX_COMPUTERNAME_LENGTH
          //    Buffer = String$(sz + 1, 0)
          //    rtn1 = GetComputerName(Buffer, sz)
          //    MyPcName = Left$(Buffer, sz)
          //    If Len(MyPcName) > 10 Then MyPcName = Left$(MyPcName, 10)

          //    '2004.08.20 ADD BSW K.Miyashita
          //    intRet = GetCureIni()
          //    If intRet = -1 Then
          //        FrmBOSSResult.LabelCuringFileErr.Visible = True
          //        With Log_Block
          //            .mod_nm = "BOSS Schedule Main"
          //            .msg = "Curing.ini file error!!"
          //        End With
          //        Call basWriteLog(0, 0, 0)
          //        End
          //    End If

          //    '' set log file name
          //    ReDim Log_Fnm(1)
          //    Log_Fnm(0) = ErrorLogFile
          //    Log_Fnm(1) = ErrorResultLogFile

          //    '' duplicate start check
          //    If App.PrevInstance Then
          //        With Log_Block
          //            .mod_nm = "BOSS Result Main"
          //            .msg = "Duplicate Starting !!"
          //        End With
          //        Call basWriteLog(0, 0, 0)
          //        End
          //    End If

          //    '' Starting Message
          //    With Log_Block
          //        .mod_nm = "BOSS Result Main"
          //        .msg = "BOSS Result process Start !!"
          //    End With
          //    Call basWriteLog(0, 0, 0)

          //    '' Connect database intRet...-1:NG / 0:OK / Over 1:NG(ErrorNumber)
          //    intRet = DBAccessConnect
          //    If intRet <> 0 Then
          //        With Log_Block
          //            .mod_nm = "BOSS Result Oracle"
          //            If intRet <> -1 Then
          //                .msg = OraSession.LastServerErrText
          //            Else
          //                .msg = "Connect Info File Not Reading !!"
          //            End If
          //        End With
          //        Call basWriteLog(0, 0, 0)
          //    End If


          //    '2004.06.04 ADD BSW K.Miyashita
          //    GHostName = GetBossIni("OracleLoginName", "Connect")

          //    Call GetMenuServerJob

          //    Counter = 0
          //    intRet = SetTimeDate()

          //    '2003.12.03 ADD BSW K.Miyashita
          //    Call GetCommonParameter

          //    '2006.07.18 Add Start SUZUKI
          //    lngSizLen = fGetS7Para()
          //    If lngSizLen < 3 Then
          //        MsgBox "CommonParameter'S7' is not right!!  Parameter5 Value='" & CStr(lngSizLen) & "' "
          //        Exit Sub

          //    End If
          //    '2006.07.18 Add End   SUZUKI

          //    '2007.11.07 Tou
          //    Call GetPlantName

          //    '2003.12.16 ADD BSW K.Miyashita
          //    Call GetCommonParameterC1

          //    '2004.06.11 ADD BSW K.Miyashita
          //    '2006.12.27 hase Call GetNamingMaster

          //    '' open form
          //    '2004.08.20 CHG & ADD BSW K.Miyashita
          //    'FrmBOSSResult.Show

          //    Load FrmBOSSResult


          //'    If (G_Df_Type = 0) Then
          //'        'CURING_RESULT_PRESS
          //'        FrmBOSSResult.CURING_RESULT_PRESS.active = True
          //'        FrmBOSSResult.CURING_RESULT_PRESS_BTMT.active = True
          //'    Else
          //        'CURING_RESULT_PRESS
          //        FrmBOSSResult.CURING_RESULT_PRESS.active = False
          //        FrmBOSSResult.CURING_RESULT_PRESS.dfno = G_DF_Cur
          //        FrmBOSSResult.CURING_RESULT_PRESS.tcdno = G_CureAct_TCD
          //        FrmBOSSResult.CURING_RESULT_PRESS.mcgno = G_CureAct_MCG
          //        FrmBOSSResult.CURING_RESULT_PRESS.active = True

          //'        FrmBOSSResult.CURING_RESULT_PRESS_BTMT.active = False
          //'        FrmBOSSResult.CURING_RESULT_PRESS_BTMT.dfno = G_DF_Cur
          //'        FrmBOSSResult.CURING_RESULT_PRESS_BTMT.active = True
          //'    End If

          //    FrmBOSSResult.Show


          //    imode = 2
          //    Call SetLogFileNm(imode)

          //On Error GoTo 0
          //Exit Sub

          //ERROR_HANDLE:
          //    rcode = Err.Number
          //    With Log_Block
          //        .mod_nm = PNAME & "Sub Main"
          //        .msg = "ERROR# = " & Str$(Err.Number) & " " _
          //             & Err.Description
          //    End With
          //    Call basWriteLog(0, 0, 0)
      }
        /// <summary>
        /// 不用
        /// </summary>
        /// <returns></returns>
      public int CheckBossDB()
      {

          string cmd;
          //Dim rtn#
          //Dim msg$
          int Count; int i; int ILot;
          string SLot;// As String * 1
          string Sireikekka;// As String * 1
          int intRet = 0;//  As Integer

          cmd = "select COUNT(*) from USER_TABLES";

          //Set OraDynaset = OraDatabase.CreateDynaset(cmd, 4&)
          // Err.Number <> 0 Then
          //If OraDatabase.LastServerErr = 3113 Or OraDatabase.LastServerErr = 3114 Or OraDatabase.LastServerErr >= 12150 Or OraSession.LastServerErr = 3113 Or OraSession.LastServerErr = 3114 Or OraSession.LastServerErr >= 12150 Then 'DB Fatal Error
          // intRet = basReConnectDB
          //End If
          //End If
          //End Function
          return intRet;
      }
        /// <summary>
        /// 总的方法，重点
        /// </summary>
        /// <param name="TcdRst1"></param>
      public void ReceiveResultMain(MesRst TcdRst1)
      {
          //Dim DBRst           As DB_CuringActualShift
          //Dim DBRstPre        As DB_CuringActualShift
          string ID1;//             As String
          string ID2;  //          As String
          int ResultChange;  //  As Integer
          string OneSideReason;//   As String
          string OkNoMark; //       As String
          int ErrorResultR = 0; //   As Integer
          int ErrorResultL = 0; //   As Integer
          string NowProductionCodeL = ""; // As String
          string NowProductionCodeR = ""; // As String

          //'2004.06.17 ADD BSW K.Miyashita
          string msg;

          //'2004.08.02 ADD BSW K.Miyashita
          int ResultChangeR = 0;
          int ResultChangeL = 0;
          //'2005.07.15 ADD BSW K.Miyashita
          int rtn;


          //On Error GoTo ERROR_HANDLE
          //rcode = 0
          //'2005.07.15 ADD BSW K.Miyashita
          //rtn = CheckBossDB();
          //'2004.06.17 ADD BSW K.Miyashita
          //ERR_DB = 0;
          //OraSession.BeginTrans

          DBRstPre DBRstPre1 = new DBRstPre();
          //'' Get error result data
          GetPreviousResultData(TcdRst1,out DBRstPre1);

          // '2004.06.17 ADD BSW K.Miyashita
          if (ERR_DB != 0)
          {
              // OraSession.ResetTrans
              msg = "GetPreviousResultData ERROR MachineNo = " + TcdRst1.MachineNo;
              m.MakeLog(1, "GetPreviousResultData", msg);
          }
          if (TcdRst1.Left_Result == "1" && int.Parse(TcdRst1.Left_Result) == DBRstPre1.ActualL)
          {
              DBRstPre1.ActualL = 0;
          }
          if ( TcdRst1.Right_Result =="1" && int.Parse(TcdRst1.Right_Result) == DBRstPre1.ActualR)
          {
              DBRstPre1.ActualR = 0;
          }


          if (int.Parse(TcdRst1.Left_Result) == DBRstPre1.ActualL && int.Parse(TcdRst1.Right_Result) == DBRstPre1.ActualR)
          {
              // '' Insert curing original data ( '01' = PRESS OPEN )
              ID1 = "01";
              ID2 = "  ";

              // '2004.08.02 CHG BSW K.Miyashita
              // 'ResultChange = 0

              if (int.Parse(TcdRst1.Left_Result) >= DBRstPre1.ActualL)
              {
                  ResultChangeL = int.Parse(TcdRst1.Left_Result) - DBRstPre1.ActualL;
              }
              else
              {
                  ResultChangeL = int.Parse(TcdRst1.Left_Result);
              }
              if (int.Parse(TcdRst1.Right_Result) >= DBRstPre1.ActualR)
              {
                  ResultChangeR = int.Parse(TcdRst1.Right_Result) - DBRstPre1.ActualR;
              }
              else
              {
                  ErrorResultR = int.Parse(TcdRst1.Right_Result);
              }

              ResultChange = ResultChangeL;

              if (ResultChange < ResultChangeR)
              {
                  ResultChange = ResultChangeR;
              }

              OneSideReason = "  ";
              OkNoMark = "01";           // ' 01 = NG [same result data ]
              InsertCuringOriginal(TcdRst1.Nonum.Trim(), TcdRst1.MachineNo.Trim(), ID1, ID2, TcdRst1.Left_ProductionCode.Trim().Substring(0, 5),
                                          TcdRst1.Right_ProductionCode.Trim().Substring(0, 5), ResultChange, OneSideReason, OkNoMark);

              //'2004.06.17 ADD BSW K.Miyashita
                  if (ERR_DB != 0)
                  {
                      string msgrt = " InsertCuringOriginal() ERROR NG MachineNo = " + TcdRst1.MachineNo;
                      m.MakeLog(1, "InsertCuringOriginal", msgrt);
                  }
          }
          else
          {
              //    '' Insert curing original data ( '01' = PRESS OPEN )
                  ID1 = "01";
                  ID2 = "  ";
              //    '2004.08.02 CHG BSW K.Miyashita
              //    'ResultChange = 0

              if ( int.Parse(TcdRst1.Left_Result) >= DBRstPre1.ActualL )
              {
                  ResultChangeL = int.Parse(TcdRst1.Left_Result) - DBRstPre1.ActualL;
              }
              else
              {
                  ResultChangeL = int.Parse(TcdRst1.Left_Result);
              }
              if (int.Parse(TcdRst1.Right_Result) >= DBRstPre1.ActualR)
              {
                  ResultChangeR = int.Parse(TcdRst1.Right_Result) - DBRstPre1.ActualR;
              }
              else
              {

                  ErrorResultR = int.Parse(TcdRst1.Right_Result);
              }

              ResultChange = ResultChangeL;

              if (ResultChange < ResultChangeR)
              {
                  ResultChange = ResultChangeR;
              }

              OneSideReason = "  ";
              OkNoMark = "  ";            // ' SP = OK
              InsertCuringOriginal(TcdRst1.Nonum.Trim(), TcdRst1.MachineNo.Trim(), ID1, ID2, TcdRst1.Right_ProductionCode.Trim().Substring(0, 5), TcdRst1.Left_ProductionCode.Trim().Substring(0, 5),
                                          ResultChange, OneSideReason, OkNoMark);

          }
          if (int.Parse(TcdRst1.Left_Result) >= DBRstPre1.ActualL)
          {

              ErrorResultL = int.Parse(TcdRst1.Left_Result) - DBRstPre1.ActualL;
          }
          else
          {
              ErrorResultL = int.Parse(TcdRst1.Left_Result);
          }
          //插入日志信息
              string con="ReceiveResultMain";
              string sdmsg = "MC NAME [L-ERROR] = TCD - PREVIOUS ==>" + TcdRst1.MachineNo + ErrorResultL + TcdRst1.Left_Result + DBRstPre1.ActualL;
              m.MakeLog(1,con,sdmsg);

          if ( int.Parse(TcdRst1.Right_Result) >= DBRstPre1.ActualR)
          {
              ErrorResultR = int.Parse(TcdRst1.Right_Result) - DBRstPre1.ActualR;
          }
          else{
              ErrorResultR = int.Parse(TcdRst1.Right_Result);
          }

          //插入日志信息
          string con1 = "ReceiveResultMain";
          string sdmsg1 = "MC NAME [L-ERROR] = TCD - PREVIOUS ==>" + TcdRst1.MachineNo + ErrorResultL + TcdRst1.Right_Result + DBRstPre1.ActualR;
          m.MakeLog(1, con1, sdmsg1);

          GetNowProductionCode(TcdRst1,out NowProductionCodeL,out NowProductionCodeR);

          //'2004.06.17 ADD BSW K.Miyashita
          if (ERR_DB != 0)
          {

              msg = "Sub GetNowProductionCode ERROR MachineNo = " + TcdRst1.MachineNo;
              m.MakeLog(1, "RECEIVE RESULT", msg);
          }


          // '<-- 2004.02.06 Add by [Kimura] ------------------------------------------------------ S
          if (!TcdRst1.Left_ProductionCode.Equals(NowProductionCodeL) || !TcdRst1.Right_ProductionCode.Equals(NowProductionCodeR))
          {
              // '' Update cycle time when size change
              basPA3PC113_2.UpdateCureCycleTimeMain(TcdRst1);


             string mod_nm ="ReceiveResultMain";
             string smsg = "SIZE CHNANGE MC NAME =" + TcdRst1.MachineNo + "[L OLD NEW] =" + NowProductionCodeL + "-" + TcdRst1.Left_ProductionCode + " [R OLD NEW] = " + TcdRst1.Right_ProductionCode + "-" + NowProductionCodeR;
             m.MakeLog(1,mod_nm,smsg);

              // '<-- 2004.02.06 Add by [Kimura] ------------------------------------------------------ E

              // '' Update Curing machine status
              UpdateCuringMachineStatus(TcdRst1, ErrorResultL, ErrorResultR);
          }

          //'' Update Curing actual shift data
          UpdateCuringActualShift(TcdRst1, ErrorResultL, ErrorResultR);

          // '' Update curing actual previous
          UpdateCuringActualShiftPrevious(TcdRst1, ErrorResultL, ErrorResultR);

        
          //'    If UCase$(PlantName) <> "BSTJ" Then    2010.01.06 Comment by tou
          //'' Update Green tire inoventory
          if (TcdRst1.Left_ProductionCode == TcdRst1.Right_ProductionCode)
          {
              // '' Left and Right production code same
              UpdateGreenTireInventory(TcdRst1.Left_ProductionCode, ErrorResultL + ErrorResultR);

              UpdateGreenTireInventory(TcdRst1.Left_ProductionCode, ErrorResultL);
              //'2004.06.17 ADD BSW K.Miyashita
            
              UpdateGreenTireInventory(TcdRst1.Right_ProductionCode, ErrorResultR);
              //'2004.06.17 ADD BSW K.Miyashita
            
          }
          ERR_DB = 0;
          string bts = "添加APS------------------------------------";
          string mss = "结束---------------------------------------------------------------------------！";
          m.MakeLog(1, bts, mss);

      }
        /// <summary>
        /// 添加方法
        /// </summary>
        /// <param name="MachineNo"></param>
        /// <param name="ID1"></param>
        /// <param name="ID2"></param>
        /// <param name="ProductionCodeL"></param>
        /// <param name="ProductionCodeR"></param>
        /// <param name="ResultChange"></param>
        /// <param name="OneSideReason"></param>
        /// <param name="OkNoMark"></param>
      public void InsertCuringOriginal(string number,string MachineNo, string ID1, string ID2, string ProductionCodeL, string ProductionCodeR, int ResultChange, string OneSideReason, string OkNoMark)
      {
          Cur_bs_shift shift = new Cur_bs_shift();
          string dSQL;
          string cur_bs_date;
          string cur_bs_shift;
          long lngRet;
          string sSQL = "";
          long RetryOK_NG;
          cur_bs_date = DateTime.Now.ToString("yyyyMMdd");
          cur_bs_shift = shift.GetShiftNow(); // DateTime.Now.ToString("hhmm");//----------------------有问题班次


          dSQL = "";
          dSQL = dSQL +"'" + DateTime.Now.ToString("yyyyMMddhhmmss")+"',";
          dSQL = dSQL +"'"+ cur_bs_date + cur_bs_shift + "',";
          dSQL = dSQL + "'"+MachineNo + "', ";
          dSQL = dSQL +"'"+ ID1 + "', ";
          dSQL = dSQL + "'"+ID2 + "', ";
          dSQL = dSQL + "'"+ProductionCodeR + "', ";
          dSQL = dSQL + "'"+ProductionCodeL + "', ";
          dSQL = dSQL + "'"+ResultChange + "', ";
          dSQL = dSQL + "'"+OneSideReason + "', ";
          dSQL = dSQL + "'"+OkNoMark + "'";


          // '' serch database
          sSQL = "INSERT INTO CuringOriginal VALUES ";
          sSQL = sSQL + "( " + dSQL + " )";

          //'' execute sql
          try
          {
              lngRet = DBUtilityOracle.DBUtilityOra.ExecuteSql(sSQL.ToString());
              if (lngRet > 0)
              {

                  Mes mes = new Mes();
                  try
                  {
                      int num = mes.updateMes(number);
                      if (num > 0)
                      {
                          string md = "更新Mes表状态";
                          string mss = "更新完毕！";
                          m.MakeLog(1,md,mss);
                      }
                  }
                  catch (Exception ex)
                  {
                      string md = "更新Mes表状态";
                      string mss = "更新失败！"+ex.ToString();
                      m.MakeLog(2, md, mss);
                  }
                  
              }
          }
          catch(Exception ex)
          { 
              ERR_DB = 1;
              string msgs = "InsertCuringOriginal";
              string msgss = ex.ToString();
              m.MakeLog(2,msgs,msgss);

          }
         
      }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="TcdRstg"></param>
        /// <param name="DBRstPre1"></param>
      public void GetPreviousResultData(MesRst TcdRstg,out DBRstPre DBRstPre1)
      {

          long lngRet;
          int open_flag;
          long RetryOK_NG;
          DBRstPre1 = new  DBRstPre();
          open_flag = 0;
          DataTable dt = new DataTable();
          string sSQL = "SELECT * FROM CuringActualPrevious";
          sSQL = sSQL + " WHERE CurePress = " + TcdRstg.MachineNo + "";
          try
          { 
              dt= DBUtilityOracle.DBUtilityOra.QueryTable(sSQL.ToString());
              if (dt.Rows.Count == 0)
              {
                  DBRstPre1.ActualL = 0;
                  DBRstPre1.ActualR = 0;
              }
              else
              {
                  DBRstPre1.Yyyymmdd = dt.Rows[0]["Yyyymmdd"].ToString();

                  DBRstPre1.Shift = dt.Rows[0]["Shift"].ToString();
                  DBRstPre1.CurePress = dt.Rows[0]["CurePress"].ToString();
                  DBRstPre1.ProductionCode = dt.Rows[0]["ProductionCode"].ToString();
                  DBRstPre1.ActualL = int.Parse(dt.Rows[0]["ActualL"].ToString());
                  DBRstPre1.ActualR = int.Parse(dt.Rows[0]["ActualR"].ToString());
                  DBRstPre1.Plan = int.Parse(dt.Rows[0]["Plan"].ToString());
              }
          }
          catch(Exception ex)
          {
              DBRstPre1.ActualL = 0;
              DBRstPre1.ActualR = 0;
              string msgss ="GetPreviousResultData";
              string msgss1 = ex.ToString();
              ERR_DB = 1;
              m.MakeLog(2,msgss,msgss1);
          }

      }
      public void UpdateCuringMachineStatus(MesRst TcdRsts, int ErrorResultL, int ErrorResultR)
      {


          //Dim DBSts           As DB_CuringMachineStatus
          //Dim OraDynaset      As OraDynaset
          //'Dim sSQL            As String
          string dSQL;
          long lngRet;
          int open_flag;
          long RetryOK_NG;
          long LTemp1;
          DB_CuringMachineStatus DBSts = new DB_CuringMachineStatus();
          //On Error GoTo ERROR_HANDLE
          // rcode = 0
          open_flag = 0;
          DataTable dtt = new DataTable();
          //'' serch database
          // '2004.08.02 CHG BSW K.Miyashita
          //'sSQL = "SELECT StatusR, BladderUseR, StatusL, BladderUseL FROM CuringMachineStatus"

          string sSQL = "SELECT StatusR, BladderUseR, StatusL, BladderUseL, ";
          sSQL = sSQL + "MOLDUSEDAYSECTORR, MOLDUSEDAYSIDER, MOLDUSEDAYSECTORL, MOLDUSEDAYSIDEL ";
          sSQL = sSQL + " FROM CuringMachineStatus";
          sSQL = sSQL + " WHERE CurePress = " + TcdRsts.MachineNo + "";
          try
          {
              dtt = DBUtilityOracle.DBUtilityOra.QueryTable(sSQL.ToString());
              if (dtt.Rows.Count > 0)
              {
                  DBSts.StatusL = dtt.Rows[0]["StatusL"].ToString();
                  DBSts.BladderUseL = dtt.Rows[0]["BladderUseL"].ToString();

                  // '2004.08.02 ADD BSW K.miyashita
                  DBSts.MoldUseDaySectorL = int.Parse(dtt.Rows[0]["MOLDUSEDAYSECTORL"].ToString());
                  DBSts.MoldUseDaySideL = int.Parse(dtt.Rows[0]["MOLDUSEDAYSIDEL"].ToString());

                  DBSts.StatusR = dtt.Rows[0]["StatusR"].ToString();
                  DBSts.BladderUseR = int.Parse(dtt.Rows[0]["BladderUseR"].ToString());

                  //'2004.08.02 ADD BSW K.miyashita
                  DBSts.MoldUseDaySectorR = int.Parse(dtt.Rows[0]["MOLDUSEDAYSECTORR"].ToString());
                  DBSts.MoldUseDaySideR = int.Parse(dtt.Rows[0]["MOLDUSEDAYSIDER"].ToString());

              }
          }
          catch(Exception ex)
          {
              string ms = "UpdateCuringMachineStatus";
              string msgs = ex.ToString();
              m.MakeLog(2, ms,msgs);
          }

          dSQL = "";
          switch (DBSts.StatusL)
          {
              case "2":
                  dSQL = dSQL + " LastOpen = '" + DateTime.Now.ToString("yyyyMMddhhmm") + "', ";
                  LTemp1 = int.Parse(DBSts.BladderUseL) + ErrorResultL;
                  if (LTemp1 > 9999999)
                  {
                      LTemp1 = 9999999;

                      string mod_nm = "UpdateCuringMachineStatus";
                      string msg = "BladderUseL>9999999.";
                      m.MakeLog(1, mod_nm, msg);
                  }
                  dSQL = dSQL + " BladderUseL = " + LTemp1 + "";
                  break;
              case "4":
                  LTemp1 = int.Parse(DBSts.BladderUseL) + ErrorResultL;
                  if (LTemp1 > 9999999)
                  {
                      LTemp1 = 9999999;
                      string mod_nm = "UpdateCuringMachineStatus";
                      string msg = "BladderUseL>9999999.";
                      m.MakeLog(1, mod_nm, msg);
                  }
                  dSQL = dSQL + " StatusL = 2,";
                  dSQL = dSQL + " LastOpen = '" + DateTime.Now.ToString("yyyyMMddhhmm") + "', ";
                  dSQL = dSQL + " BladderUseL = " + LTemp1;
                  break;

          }
          // '2004.08.02 ADD BSW K.miyashita
          LTemp1 = DBSts.MoldUseDaySectorL + ErrorResultL;
          if (LTemp1 > 9999999)
          {
              LTemp1 = 9999999;
              string mod_nm = "UpdateCuringMachineStatus";
              string msg = "MoldUseDaySectorL>9999999.";
              m.MakeLog(1, mod_nm, msg);
          }
          dSQL = dSQL + ", MOLDUSEDAYSECTORL = " + LTemp1;
          LTemp1 = DBSts.MoldUseDaySideL + ErrorResultL;
          if (LTemp1 > 9999999)
          {
              LTemp1 = 9999999;
              string mod_nm = "UpdateCuringMachineStatus";
              string msg = "MoldUseDaySideL>9999999.";
              m.MakeLog(1, mod_nm, msg);
          }
          dSQL = dSQL + ", MOLDUSEDAYSIDEL = " + LTemp1;


          if (int.Parse(TcdRsts.Left_Result) > 0)
          {
              //'' serch database
              sSQL = "UPDATE CuringMachineStatus SET ";
              sSQL = sSQL + dSQL;
              sSQL = sSQL + " WHERE CurePress = " + TcdRsts.MachineNo + "";

              //'' execute sql
              lngRet = DBUtilityOracle.DBUtilityOra.ExecuteSql(sSQL.ToString());
          }

          dSQL = "";
          switch (DBSts.StatusR)
          {
              case "2":
                  dSQL = dSQL + " LastOpen =" + DateTime.Now.ToString("yyyyMMddhhmm") + ", ";
                  LTemp1 = DBSts.BladderUseR + ErrorResultR;
                  if (LTemp1 > 9999999)
                  {
                      LTemp1 = 9999999;
                      string mod_nm = "UpdateCuringMachineStatus";
                      string msg = "BladderUseR>9999999.";
                      m.MakeLog(1, mod_nm, msg);
                  }
                  dSQL = dSQL + " BladderUseR = " + LTemp1;
                  break;
              case "4":
                  dSQL = dSQL + " StatusR = 2, ";
                  dSQL = dSQL + " LastOpen = " + DateTime.Now.ToString("yyyyMMddhhmm") + ", ";
                  LTemp1 = DBSts.BladderUseR + ErrorResultR;
                  if (LTemp1 > 9999999)
                  {
                      LTemp1 = 9999999;
                      string mod_nm = "UpdateCuringMachineStatus";
                      string msg = "BladderUseR>9999999.";
                      m.MakeLog(1, mod_nm, msg);
                  }
                  dSQL = dSQL + " BladderUseR = " + LTemp1;
                  break;
          }

          //'2004.08.02 ADD BSW K.miyashita
          LTemp1 = DBSts.MoldUseDaySectorR + ErrorResultR;
          if (LTemp1 > 9999999)
          {
              LTemp1 = 9999999;
              string mod_nm = "UpdateCuringMachineStatus";
              string msg = "MOLDUSEDAYSECTORR>9999999.";
              m.MakeLog(1, mod_nm, msg);
          }
          dSQL = dSQL + ", MOLDUSEDAYSECTORR = " + LTemp1;
          LTemp1 = DBSts.MoldUseDaySideR + ErrorResultR;
          if (LTemp1 > 9999999)
          {
              LTemp1 = 9999999;
              string mod_nm = "UpdateCuringMachineStatus";
              string msg = "MOLDUSEDAYSIDER>9999999.";
              m.MakeLog(1, mod_nm, msg);
          }
          dSQL = dSQL + ", MOLDUSEDAYSIDER = " + LTemp1;


          if (int.Parse(TcdRsts.Right_Result) > 0)
          {
              //'' serch database
              sSQL = "UPDATE CuringMachineStatus SET ";
              sSQL = sSQL + dSQL;
              sSQL = sSQL + " WHERE CurePress = " + TcdRsts.MachineNo + "";

              // '' execute sql
              lngRet = DBUtilityOracle.DBUtilityOra.ExecuteSql(sSQL.ToString());
          }
         
      }
       /// <summary>
      /// 更新CuringActualShift
       /// </summary>
       /// <param name="TcdRst1"></param>
       /// <param name="ErrorResultL"></param>
       /// <param name="ErrorResultR"></param>
      public void UpdateCuringActualShift(MesRst TcdRst1, int ErrorResultL, int ErrorResultR)
      {
          //Dim DBSts           As DB_CuringMachineStatus
          //Dim OraDynaset      As OraDynaset
          //'Dim sSQL            As String
          string dSQL;
          long lngRet;
          string ProductionCode;
          string cur_bs_date;
          string cur_bs_shift;
          int resultL;
          int resultR;
          int open_flag;
          long RetryOK_NG;
          int iloop;
          int idx;
          int wkResultL;
          int wkResultR;

          open_flag = 0;
          Cur_bs_shift shif = new Cur_bs_shift(); 
          cur_bs_date = DateTime.Now.ToString("yyyyMMdd");
          cur_bs_shift = shif.GetShiftNow(); //DateTime.Now.ToString("hhmm");

          //'----------- '2004.07.14 k.hase add -----------
          if (TcdRst1.Left_ProductionCode != "" && TcdRst1.Right_ProductionCode != "" && !TcdRst1.Left_ProductionCode.Equals(TcdRst1.Right_ProductionCode))
          {
              iloop = 2;
          }
          else
          {
              iloop = 1;
          }

          // '----------- '2004.07.14 k.hase add -----------

          //For idx = 1 To iloop                                                    '2004.07.14 k.hase add
          // '----------- '2004.07.14 k.hase add -----------
          for (idx = 1; idx < iloop + 1; idx++)
          {
              if (idx == 1)
              {
                  if (TcdRst1.Left_ProductionCode != "" && TcdRst1.Right_ProductionCode != "" && TcdRst1.Left_ProductionCode.Equals(TcdRst1.Right_ProductionCode))
                  {
                      ProductionCode = TcdRst1.Left_ProductionCode;
                      wkResultL = ErrorResultL;
                      wkResultR = ErrorResultR;
                  }
                  else if (TcdRst1.Left_ProductionCode != "" && TcdRst1.Right_ProductionCode != "" && !TcdRst1.Left_ProductionCode.Equals(TcdRst1.Right_ProductionCode))
                  {
                      ProductionCode = TcdRst1.Left_ProductionCode;
                      wkResultL = ErrorResultL;
                      wkResultR = 0;
                  }
                  else
                  {
                      if (TcdRst1.Left_ProductionCode != "")
                      {
                          ProductionCode = TcdRst1.Left_ProductionCode;
                      }
                      else
                      {
                          ProductionCode = TcdRst1.Left_ProductionCode;
                      }
                      wkResultL = ErrorResultL;
                      wkResultR = ErrorResultR;
                  }
              }
              else
              {
                  ProductionCode = TcdRst1.Right_ProductionCode;
                  wkResultL = 0;
                  wkResultR = ErrorResultR;
              }
              //'----------- '2004.07.14 k.hase add -----------
              DataTable dt = new DataTable();
              //'' serch database
              string sSQL = "SELECT * FROM CuringActualShift";
              sSQL = sSQL + " WHERE CurePress      = '" + TcdRst1.MachineNo + "'";
              sSQL = sSQL + " AND   Yyyymmdd       = '" + cur_bs_date + "'";
              sSQL = sSQL + " AND   Shift          = '" + cur_bs_shift + "'";
              sSQL = sSQL + " AND   ProductionCode = '" + ProductionCode + "'";

              dt = DBUtilityOracle.DBUtilityOra.QueryTable(sSQL.ToString());
              dSQL = "";
              //'' No serch data
              //If OraDynaset.EOF Then---------------------------------
              if (dt.Rows.Count == 0)
              {
                  dSQL = dSQL + "'" + cur_bs_date + "', ";
                  dSQL = dSQL + "'" + cur_bs_shift + "', ";
                  dSQL = dSQL + "'" + TcdRst1.MachineNo.Trim() + "', ";
                  dSQL = dSQL + "'" + ProductionCode.Trim() + "', ";
                  //'2004.07.14 k.Hase dSQL = dSQL & Str$(ErrorResultL) & ", "
                  //'2004.07.14 k.Hase dSQL = dSQL & Str$(ErrorResultR) & ", "
                  dSQL = dSQL + "" + wkResultL + ", "; //'2004.07.14 k.Hase
                  dSQL = dSQL + "" + wkResultR + ", ";
                  dSQL = dSQL + "0";

                  sSQL = "INSERT INTO CuringActualShift VALUES (" + dSQL + " )";
              }
              else
              {
                  resultL = int.Parse(dt.Rows[0]["ActualL"].ToString());//OraDynaset.Fields("ActualL")
                  resultR = int.Parse(dt.Rows[0]["ActualR"].ToString()); //OraDynaset.Fields("ActualR")
                  //'2004.07.14 k.Hase dSQL = dSQL & " ActualL = " & Str$(resultL + ErrorResultL) & ", "
                  //'2004.07.14 k.Hase dSQL = dSQL & " ActualR = " & Str$(resultR + ErrorResultR)
                  dSQL = dSQL + " ActualL = " + (resultL + wkResultL) + ", "; //'2004.07.14 k.Hase
                  dSQL = dSQL + " ActualR = " + (resultR + wkResultR);     //'2004.07.14 k.Hase
                  sSQL = "UPDATE CuringActualShift SET " + dSQL + " WHERE CurePress = '" + TcdRst1.MachineNo.Trim() + "'"
                       + " and   Yyyymmdd       = '" + cur_bs_date + "'"
                       + " and   Shift          = '" + cur_bs_shift + "'"
                       + " and   ProductionCode = '" + ProductionCode.Trim() + "'";
              }
              try
              {
                  lngRet = DBUtilityOracle.DBUtilityOra.ExecuteSql(sSQL.ToString()); 
              }
              catch(Exception ex)
              {
                  string bt = "void UpdateCuringActualShift";
                  string mgg = ex.ToString();
                  m.MakeLog(2,bt,mgg);

              }
              
              
          }
      }
      public void UpdateCuringActualShiftPrevious(MesRst TcdRstss, int ErrorResultL, int ErrorResultR)
      {
          //Dim DBSts           As DB_CuringMachineStatus
          //Dim OraDynaset      As OraDynaset
          //'Dim sSQL            As String
          string dSQL="";
          long lngRet=0;
          string ProductionCode;
          string cur_bs_date;
          string cur_bs_shift;
          long RetryOK_NG;

          cur_bs_date = DateTime.Now.ToString("yyyyMMdd");
          cur_bs_shift = DateTime.Now.ToString("hhmm");

          ProductionCode = TcdRstss.Left_ProductionCode;
          if (ProductionCode == "" && ProductionCode.Equals(TcdRstss.Left_ProductionCode))
          {
              ProductionCode = TcdRstss.Right_ProductionCode;
          }

          //'    dSQL = dSQL & " ActualL = " & Str$(TcdRst.result.left.result + ErrorResultL) & ", "
          //'    dSQL = dSQL & " ActualR = " & Str$(TcdRst.result.right.result + ErrorResultR)
          dSQL = dSQL + " ActualL = " + TcdRstss.Left_Result + ", ";
          dSQL = dSQL + " ActualR = " + TcdRstss.Right_Result;
          string sSQL = "UPDATE CuringActualPrevious SET " +
                dSQL + " WHERE CurePress      = " + TcdRstss.MachineNo + "";
          //'' execute sql
          lngRet = DBUtilityOracle.DBUtilityOra.ExecuteSql(sSQL.ToString());

          if (lngRet == 0)
          {
              dSQL = "" + cur_bs_date + ", ";
              dSQL = dSQL + "" + cur_bs_shift + ", ";
              dSQL = dSQL + "" + TcdRstss.MachineNo + ", ";
              dSQL = dSQL + "" + ProductionCode + ", ";
              dSQL = dSQL + "" + ErrorResultL + ", ";
              dSQL = dSQL + "" + ErrorResultR + ", ";
              dSQL = dSQL + "0";

              sSQL = "INSERT INTO CuringActualPrevious VALUES "
                   + "(" + dSQL + " )";
              // '' execute sql
              try
              { 
                   lngRet = DBUtilityOracle.DBUtilityOra.ExecuteSql(sSQL.ToString());
              }
              catch(Exception ex)
              {
                  string bt = "void UpdateCuringActualShiftPrevious";
                  string mssg = ex.ToString();
                  m.MakeLog(2, bt, mssg);


              }
             
          }

      }
        /// <summary>
        /// 更新方法
        /// </summary>
        /// <param name="ProductionCode"></param>
        /// <param name="result"></param>
      public void UpdateGreenTireInventory(string ProductionCode, int result)
      {
          //Dim DBLot           As DB_CuringScheduleLot
          //Dim DBGt            As DB_GreenTireInventory
          //Dim OraDynaset      As OraDynaset
          //'Dim sSQL            As String
          string dSQL;
          long lngRet;
          long CuringTotal;
          long NowInventory;
          string msg;
          int open_flag;
          long RetryOK_NG;
          long LTemp;
          //On Error GoTo ERROR_HANDLE
          //    rcode = 0
          open_flag = 0;
          DB_GreenTireInventory DBGt = new DB_GreenTireInventory();
          DataTable dt = new DataTable();
          //'' serch database
          string sSQL = "SELECT BuildingTotal, CuringTotal, GTScrapTotal, OtherScrapTotal ";
          sSQL = sSQL + " FROM GreenTireInventory";
          sSQL = sSQL + " WHERE BuildingSize Like '" + ProductionCode.Trim() + "'%";
          //'    sSQL = sSQL+ " AND   ProductionGroup = " & Chr(39) & Trim$(DBLot.ProductionGroup) & Chr(39)
          sSQL = sSQL + " AND   CurrentStatus   =0";
          try
          {
              dt = DBUtilityOracle.DBUtilityOra.QueryTable(sSQL.ToString());
          }
          catch (Exception ex)
          {
              string g = "void UpdateGreenTireInventory";
              string msdd = ex.ToString();
              m.MakeLog(2,g,msdd);

          }

          if (dt.Rows.Count > 0)
          {
              DBGt.BuildingTotal = int.Parse(dt.Rows[0]["BuildingTotal"].ToString()); //IIf(IsNull(OraDynaset.Fields("BuildingTotal")), _
              // "", OraDynaset.Fields("BuildingTotal"))
              DBGt.CuringTotal = int.Parse(dt.Rows[0]["CuringTotal"].ToString()); //IIf(IsNull(OraDynaset.Fields("CuringTotal")), _
              //  0, OraDynaset.Fields("CuringTotal"))
              DBGt.GTScrapTotal = int.Parse(dt.Rows[0]["GTScrapTotal"].ToString()); //IIf(IsNull(OraDynaset.Fields("GTScrapTotal")), _
              //0, OraDynaset.Fields("GTScrapTotal"))
              DBGt.OtherScrapTotal = int.Parse(dt.Rows[0]["OtherScrapTotal"].ToString()); //IIf(IsNull(OraDynaset.Fields("OtherScrapTotal")), _
              //0, OraDynaset.Fields("OtherScrapTotal"))
              //OraDynaset.Close
              //Set OraDynaset = Nothing:       open_flag = 0

              LTemp = DBGt.CuringTotal + result;
              if (LTemp > 9999999)
              {
                  LTemp = 0;

                  string mod_nm = "UpdateGreenTireInventory";
                  string msg1 = "CuringTotal+Result>9999999." + ProductionCode;
                  m.MakeLog(1, mod_nm,msg1);
              }
              else
              {
                  LTemp = result;
              }

              CuringTotal = DBGt.CuringTotal + result;
              NowInventory = DBGt.BuildingTotal - CuringTotal - DBGt.GTScrapTotal - DBGt.OtherScrapTotal;

              dSQL = "";
              //''        dSQL = dSQL & " CuringTotal = " & Str$(CuringTotal) & ", "                                '' 2005.02.01 K.Takayama DEL
              //''        dSQL = dSQL & " NowInventory = " & Str$(NowInventory) & ", "                              '' 2005.02.01 K.Takayama DEL
              dSQL = dSQL + " CuringTotal = (CuringTotal + " + LTemp + "), ";                       //'' 2005.02.01 K.Takayama ADD
              dSQL = dSQL + " NowInventory = NowInventory - (( CuringTotal + " + result + " ) - CuringTotal), ";       // '' 2005.02.01 K.Takayama ADD
              dSQL = dSQL + " LastUpdate = " + DateTime.Now.ToString("yyyymmddhhnn") + ", ";
              dSQL = dSQL + " LastUpdateID = 1";

              sSQL = "UPDATE GreenTireInventory SET ";
              sSQL = sSQL + dSQL;
              // '2006.07.18 Chg Start SUZUKI
              sSQL = sSQL + " WHERE SUBSTR(BuildingSize,1," + lngSizLen + ") = " + ProductionCode + "";
              //'        sSQL = sSQL & " WHERE BuildingSize    = " & Chr(39) & Trim$(ProductionCode) & Chr(39)
              // '2006.07.18 Chg End   SUZUKI
              //'        sSQL = sSQL & " AND   ProductionGroup = " & Chr(39) & Trim$(DBLot.ProductionGroup) & Chr(39)
              sSQL = sSQL + " AND   CurrentStatus   = 0";

              //'' execute sql
              try
              { lngRet = DBUtilityOracle.DBUtilityOra.ExecuteSql(sSQL.ToString());}
              catch(Exception ex)
              {
                  string bt = "UpdateGreenTireInventory";
                  string con = ex.ToString();
                  m.MakeLog(2, bt, con);
              }
              
             
          }
         
      }
      private long fGetS7Para()
      {
          long lngRecCnt;
          //Dim objOraDyna      As OraDynaset
          string strSql;
          long lngAns = 0;
          DataTable de = new DataTable();
          strSql = "SELECT ";
          strSql = strSql + " Parameter5 AS Prm5 ";
          strSql = strSql + "FROM CommonParameter ";
          strSql = strSql + "WHERE ParameterKey = 'S7' ";
          de = DBUtilityOracle.DBUtilityOra.QueryTable(strSql.ToString());
          //Set objOraDyna = OraDatabase.CreateDynaset(strSql, 4&)
          //With objOraDyna
          //    lngRecCnt = .RecordCount
          //    lngAns = 4
          //    If lngRecCnt > 0 Then
          //        lngAns = IIf(IsNull(.Fields("Prm5")) = True, 4, .Fields("Prm5"))

          //    End If

          //End With

          //fGetS7Para = lngAns

          //Exit Function
          return lngAns;
      }
        /// <summary>
        /// 
        /// </summary>
      public void GetPlantName()
      {
          // Dim cmd$
          // Dim pcount
          // Dim NamingDynaset      As OraDynaset

          //    cmd$ = "Select Naming1,Naming2 from NamingMaster"
          //    cmd$ = cmd$ & " Where Classification1='B'"
          //    cmd$ = cmd$ & " and Classification2='00'"
          //    cmd$ = cmd$ & " and Classification3='00'"

          //    Set NamingDynaset = OraDatabase.CreateDynaset(cmd$, 0&)
          //    pcount = NamingDynaset.RecordCount
          //    If pcount > 0 Then
          //        FontFontName = NamingDynaset.Fields("Naming1")
          //        PlantName = Trim$(NamingDynaset.Fields("Naming2"))
          //    Else
          //        FontFontName = "System"
          //        PlantName = "????"
          //    End If
          //End Function
      }
    }
}

